// $(document).ready(function() {
//     $(".collection").click(function () {
        console.log("收藏夹加载")
        var totalIndex=1;
        var maxIndex;
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/shop-api/goods/collection",
            data: {pageIndex: 1, pageSize: 6},
            success: function (resp) {
                console.log(resp);
                Drawing(resp.data);
            }
        })
        function forPage() {
            console.log("下一页")
            totalIndex=totalIndex+1;
            if (totalIndex<=0){totalIndex=1;}
            if (totalIndex>=maxIndex){totalIndex=maxIndex;}
            pageCollection(totalIndex);
        }
        function backPage() {
            console.log("上一页")
            totalIndex=totalIndex-1;
            if (totalIndex<=0){totalIndex=1;}
            if (totalIndex>=maxIndex){totalIndex=maxIndex;}
            pageCollection(totalIndex);
        }
        function pageCollection(pageIndex) {
            console.log("加载其他页");
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/shop-api/goods/collection",
                data: {pageIndex: pageIndex, pageSize: 6},
                success: function (resp) {
                    maxIndex=resp.code;
                    totalIndex=pageIndex;
                    Drawing(resp.data);
                }
            })
        }
    // })

    function Drawing(goodsList) {

        let map = goodsList.map(function (item) {
            let gimg =item.gimg;
            let gprice =item.gprice;
            let gname =item.gname;
            let gtype =item.gtype;
            let li =
            "<figure class=\"gallery-grid__item category-concept\" style=\"float: left;margin-right: 10px;margin-left: 10px\">\n" +
            "<div class=\"gallery-grid__image-wrap\">\n" +
            "<img class=\"gallery-grid__image cover lazyload\" src="+gimg+" data-zoom alt=\"\" />\n" +
            "</div>\t\n" +
            "<figcaption class=\"gallery-grid__caption\">\n" +
            "<h4 class=\"title title&#45;&#45;h6 gallery-grid__title\">"+gname+"</h4>\n" +
            "<span class=\"gallery-grid__category\">" + gprice +"</span>\n" +
            "</figcaption>\n" +
            "</figure>";
            console.log("正在收藏夹渲染");
            return li;
        });
        $("#collections").html(map.join(""));
        console.log("收藏夹渲染成功");




        // let templateGoodsHtml = $("#template_goods").html();
        // let goodsListHtml = "";
        // let tempGoodsHtml;
        // $.each(goodsList, function (index, goods) {
        //     console.log(goods);
        //     //后台数据填充到模板中
        //     tempGoodsHtml = templateGoodsHtml.replace(/{name}/g, goods.gname)
        //         .replace(/{img}/g, goods.gimg)
        //         .replace(/{type}/g, goods.gtype)
        //         .replace(/{price}/g, goods.gprice);
        //     console.log(tempGoodsHtml);
        //     goodsListHtml += tempGoodsHtml;
        // });
        // //拼接商品展示html
        // //html 填充到页面当中
        // $(".items").html(goodsListHtml);
    }

// })